<?php

class Posts_model extends CI_Model {

    public $table = "";
    //put your code here
    function __construct() {
        parent::__construct();
        $this->table = MYSQL_TABLE_PREFLIX.TABLE_USER2_POSTS;
    }

    function GetAll($offset = 0, $limit = 10) {
        $this->db->from($this->table);
        $this->db->order_by("PostDate", "asc");
        $this->db->limit($limit,$offset);
        $query = $this->db->get();
        return $query->result_array();
    }
    
    function Get($data){
        $query = $this->db->get_where($this->table, $data);
        return $query->result_array();
    }
    
    function Get_Advanced($select = '*', $where = array(), $order_by = "UserFullname desc", $limit = 10, $offset = 0){
        $query = $this->db->select($select)->order_by($order_by)->get_where($this->table, $where,$limit, $offset);
        return $query->result_array();
    }

    function Insert($data) {
        $this->db->insert($this->table, $data);
    }
    
    function Delete($data) {
        $this->db->delete($this->table, $data);
    }
    
    function Update($data, $where){
        $this->db->where($where)->update($this->table,$data);
    }
    
    function Query($AddQuery,$order = "UserFullname desc", $limit = 20, $offset = 0){
        $query = "select * from ".$this->table." where ".$AddQuery." order by $order"." limit $limit". " offset $offset";
        $query = $this->db->query($query);
        return $query->result_array();
    }
    
    function Get_Num($data){
        return $this->db->where($data)->count_all_results($this->table);
    }
}
